package junit.framework;

/**
 * Thrown when an assert equals for Strings failed.
 * 
 * Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com
 *
 * 当断言 String 相同失败 ，抛出一个异常
 */
public class ComparisonFailure extends AssertionFailedError {
	/**
	 * 最大的内容长度为20
	 */
	private static final int MAX_CONTEXT_LENGTH= 20;
	private static final long serialVersionUID= 1L;

	/**
	 * 期望的str
	 */
	private String fExpected;
	/**
	 * 实际的str
	 */
	private String fActual;

	/**
	 * Constructs a comparison failure.
	 * @param message the identifying message or null  描述信息，可以为空，会在异常的抛出的时候显示
	 * @param expected the expected string value
	 * @param actual the actual string value
	 */
	public ComparisonFailure(String message, String expected, String actual) {
		super (message);
		fExpected= expected;
		fActual= actual;
	}
	
	/**
	 * Returns "..." in place of common prefix and "..." in
	 * place of common suffix between expected and actual.
	 * 
	 * @see Throwable#getMessage()
	 */
	public String getMessage() {
		return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage());
	}
	
	/**
	 * Gets the actual string value
	 * @return the actual string value
	 */
	public String getActual() {
		return fActual;
	}
	/**
	 * Gets the expected string value
	 * @return the expected string value
	 */
	public String getExpected() {
		return fExpected;
	}
}